﻿using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using QuanLyHocPhi.Model.Mapping;
using System.Data.Common;

namespace QuanLyHocPhi.Model
{
    public partial class QLHPEntities : DbContext
    {
        public QLHPEntities()
            // : base("QLHP_LuatContext")
            : base(GUI.HeThong.FormThietLapChuoiKetNoi.AppDbConnection, true)
        {
            // đọc chuỗi connectionstring đã mã hoá

            // giải mã

            // tạo ...
        }

        public QLHPEntities(string providerName, string connectionString)
            : base(CreateDbConnection(providerName, connectionString), true)
        { }

        public static DbConnection CreateDbConnection(string dbProvider, string connectionString)
        {
            var dbFactory = DbProviderFactories.GetFactory(dbProvider);
            var dbConnection = dbFactory.CreateConnection();
            dbConnection.ConnectionString = connectionString;
            return dbConnection;
        }
    }
}